package com.phonebills.dao;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * Mybatis 的BaseDao
 * @author LIU
 * @version 1.0 2017-10-19
 */
public class BaseMapper {

	/**
	 * 获取session
	 *TODO
	 *LIU
	 * @param path
	 * @return
	 *下午11:31:35
	 */
	public SqlSession getSession(String path){
		Reader reader = null;
		SqlSession session = null;
		try {
			reader = Resources.getResourceAsReader(path);
			SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
			SqlSessionFactory factory = builder.build(reader);
			session = factory.openSession();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				reader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return session;
	}
	
}
